package com.shuqi.activity.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.shuqi.controller.R;
import com.shuqi.model.bean.BuyRecordInfo;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 购买章节明细
 * 
 * @author zhuchen
 * 
 */
public class PayChapterHistoryAdapter extends BaseAdapter {

    private List<BuyRecordInfo> list;
    private LayoutInflater inflater;

    public PayChapterHistoryAdapter(Context context) {
        this.inflater = LayoutInflater.from(context);
    }

    public void setList(List<BuyRecordInfo> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        if (list != null && list.get(position) != null) {
            return list.get(position);
        } else {
            return null;
        }
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View view = null;
        if (convertView != null) {
            view = convertView;
        } else {
            view = inflater.inflate(R.layout.item_paychapterhistory, parent, false);
        }
        Holder holder = (Holder) view.getTag();
        if (holder == null) {
            holder = new Holder();
            holder.item_paychapterhistory_paychapter =
                    (TextView) view.findViewById(R.id.item_paychapterhistory_paychapter);
            holder.item_paychapterhistory_time =
                    (TextView) view.findViewById(R.id.item_paychapterhistory_time);
        }
        // 设置数据
        holder.item_paychapterhistory_paychapter.setText(list.get(position).getInfo());
        if (!TextUtils.isEmpty(list.get(position).getTime())) {
            holder.item_paychapterhistory_time.setText(list.get(position).getTime());
        }
        return view;
    }

    private static class Holder {
        private TextView item_paychapterhistory_paychapter;// 最近购买
        private TextView item_paychapterhistory_time;// 购买时间
    }

}
